home *** CD-ROM | disk | FTP | other *** search
- One if the most powerful features of BATch processing has gone too long
- undocumented.
-
- The DOS Environment is accessible for use in BATs.
-
- The standard keywords COMSPEC, PATH, PROMPT et al can all be read and set.
- New keywords can be set and checked within BATs. The keywords are saved
- across BAT executions.
-
- For instance BATs can check which screen is active using SET conventions
- as follows:
-
- . NOTE leading and trailing Percent signs
- IF %SCREEN% == MONO GOTO COLOR
- IF %SCREEN% == COLOR GOTO MONO
- :COLOR
- SET SCREEN=COLOR
- . NOTE no spaces around '=' in SET
- MODE CO80
- EXIT
- :MONO
- SET SCREEN=MONO
- MODE MONO
- EXIT
- . SCREEN is set and saved across BAT executions
-
- Another example using a link convention allows BATs to call BATs:
-
- *****CALL.BAT*****
-
- IF NOT %BATLABEL% == . GOTO %BATLABEL%
- . note BATLABEL is assumed to be set to '.' as a null value
- ECHO DO SOME STUFF HERE
- SET BATCALR=%0
- . give the called BAT my name to get back
- . then leave word where to come back to
- SET BATLABEL=RETURN
- . set further parms to save %1 thru %9 if necessary
- CALLED
- :RETURN
- ECHO FINISH UP HERE AFTER RETURN
-
- *****CALLED.BAT*****
-
- ECHO DO STUFF WE WERE CALLED TO DO
- . return to caller
- %BATCALR%
- . separate keywords will be necessary if further calls
- . will be made
-
- A note of caution (this is documented), the environment at boot time,
- is limited (I believe to only 128 bytes). If any resident modules are
- installed (i.e. PRINT, MODE, or GRAPHICS) the area cannot be expanded.
- You can SET enough variables from within AUTOEXEC.BAT to get enough
- space to get by.
-
- I would also recommend setting up a set of conventions and preinitializing
- the parms you'll use to '.'; Null parameters are removed from the
- environment.
-
- In summary -
- The rules are simple
- SET a parm without percent signs
- refer to them by enclosing them in percent signs
-
- I hope this discovery will generate a lot of re-thinking some BAT
- techniques.
-
-
- Bob Becksted
-
- s discovery will generate a lot of re-thinking some BAT
- techniques.
-
-
- Bob Becksted
-
-